// let n: number;
// n = 8;
let n: number = 8.8;
// n = true;
console.log(n);
let s: string = "hello"; //字符串
console.log(s);
let flag: boolean = false;
console.log(flag);
let age: undefined;
console.log(age);
let p: null = null;
console.log(p);
let x: symbol = Symbol("Hello");
console.log(x);

let stu: Date = new Date();
console.log(stu);

// 数组类型: string 是 String 的别名
let arr: number[] = [12, 34, 56, 67, 89];
console.log(arr);
let arr3: Array<String> = ["admin", "123", "admin3"];
console.log(arr3);

// 数组元素可以是number和string类型
let arr2: (number | string | boolean)[] = [12, 34, "admin", 13, true];
console.log(arr2);
let arr4: number | string[] = 12;
arr4 = ["23", "45", "admin"];
console.log(arr4);

//以上js类型

// 复杂类型|联合类型
type customType = (number | string)[];
let arr5: customType = [12, 34, 45, "admin", "123", "admin3"];
console.log(arr5);
function show2() {}
let fn = () => {};
// 函数的返回值和参数的类型
function show(a: number, b: number): number {
  return a + b;
}
let x2: number = show(1, 2);
console.log(x2 + 1);

// 函数表达式
const init2 = (a: number, b: number): number => {
  return a + b;
};
x2 = init2(2, 3);
console.log(x2 + 5);

// 使用就比较少
const add: (a: number, b: number) => number = (a, b) => {
  return a + b;
};
x2 = add(1, 3);
console.log(x2 + 3);

// 返回值为void
function show3(num: number): void {
  console.log(num + 1);
}
show3(2);

// 可选参数
function show4(num1: number, num2?: number, num3?: number): number {
  console.log(num1, num2, num3);

  return 8;
}
// x2 = show4(1);
// x2 = show4(1, 88);
x2 = show4(22, 33, 44);
console.log(x2);

// 自定义对象类型
class Person {
  name: string;
  age: number;
  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }
}
let person: Person = new Person("张三", 10);
console.log(person);
